#include "CLoginView.h"
#include "CGameScene.h"

CLoginView::CLoginView() : background(NULL), pbPlay(NULL), pbFacebook(NULL)
{

}

CLoginView::~CLoginView()
{
	CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, BUTTON_CLICK_EVENT);
	CC_SAFE_RELEASE_NULL(background);
	CC_SAFE_RELEASE_NULL(pbPlay);
	CC_SAFE_RELEASE_NULL(pbFacebook);
}

bool CLoginView::init()
{
	if (!CCLayer::init())
	{
		return false;
	}
	background = CCSprite::create("login.jpg");
	background->setAnchorPoint(ccp(0, 0));
	background->retain();
	addChild(background);

	pbPlay = CButton::create("play.png");
	pbPlay->pszButtonName = "pbPlay";
	pbPlay->retain();
	addChild(pbPlay);
	pbPlay->setPosition(ccp(320, 1136 - 660));
	CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(CLoginView::onButtonClick), BUTTON_CLICK_EVENT, NULL);

	pbFacebook = CButton::create("facebook.png");
	pbFacebook->setPosition(ccp(320, 1136 - 800));
	pbFacebook->pszButtonName = "pbFacebook";
	pbFacebook->retain();
	addChild(pbFacebook);
	return true;
}

void CLoginView::onButtonClick(CCObject* pSender)
{
	if (pSender == pbPlay)
	{
		CGameScene& scene = CGameScene::getInstance();
		scene.changeView(scene.getGameView());
	}
	else if (pSender == pbFacebook)
	{
		
	}
}
